package com.kede.api.stand.controller.user;

import com.kede.api.stand.pub.ActiveLineHolde;
import com.kede.api.stand.service.IUserManageService;
import com.kede.pojo.ResHttp;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author:Pr.li
 * @Date: create in 2023/6/26 21:10
 */
@RestController
@RequestMapping("user")
public class UserController {

    @Resource
    private IUserManageService userManageService;

    /**
     * 用户可以下单的普通置换数
     * @param userid
     * @return
     */
    @GetMapping("getUserCanZhiNum")
    public ResHttp getUserCanZhiNum(Integer userid){
        return userManageService.getUserCanZhiNum(userid);
    }


    /**
     * 用户可以下的现金置换数
     * @param userid
     * @return
     */
    @GetMapping("getUserMoneyOrderCanZhiNum")
    public ResHttp getUserMoneyOrderCanZhiNum(Integer userid){
        return userManageService.getUserMoneyOrderCanZhiNum(userid);
    }

    @GetMapping("upAddressByUserId")
    public ResHttp upAddressByUserId(Integer userId,String lng,String lat){
        return userManageService.upAddressByUserId(userId,lng,lat);
    }

    /**
     * 用户打开应用活动 埋点
     * typeCode 对应 AppIdTypeEnum的type
     **/
    @GetMapping("onLine")
    public void onLine(Integer userId,Integer adcode,String typeCode){
        ActiveLineHolde.onLineUser.compute(userId,(k, v)->{
            if(v == null){
                return 1;
            }else{
                return ++v;
            }
        });
        ActiveLineHolde.onLineAdcode.compute(adcode,(k,v)->{
            if(v == null){
                return 1;
            }else{
                return ++v;
            }
        });
        ActiveLineHolde.onLineAppType.compute(typeCode,(k,v)->{
            if(v == null){
                return 1;
            }else{
                return ++v;
            }
        });
    }





}
